﻿#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "thread/SerialThread.h"
#include <QComboBox>
#include <QSerialPortInfo>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    //获取电脑串口
    initAllSericalMsg();
    test();
}

MainWindow::~MainWindow()
{
    delete ui;
}

//点击了“打开串口按钮”
void MainWindow::on_openSericalBtn_clicked() {
    QString currentBaudRate = ui->BaudRateComboBox->currentText();
    qDebug() << "on_openSericalBtn_clicked......" << currentBaudRate;
}

//获取电脑串口
void MainWindow::initAllSericalMsg() {
    QList<QSerialPortInfo> allSerial=QSerialPortInfo::availablePorts();
    for (const QSerialPortInfo & s: allSerial) {
        ui->comboBox->addItem(s.portName());
    }
}

//测试
void MainWindow::test() {
    SerialThread* serialThread = new SerialThread(this);
    connect(serialThread, &SerialThread::finished, serialThread, &SerialThread::deleteLater);
    serialThread->start();
}